﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess.Operate
{
    public class DA_Report_BuyStandAlone_Inherit:SqlInteractionBase
    {
        #region 查询全部字典
        /// <summary>
        /// 查询全部字典
        /// </summary>
        /// <returns></returns>
        public DataSet FindALLByTypeId(string Report_BuyStandAlone_ExchangeTypeID, string Report_BuyStandAlone_ReportNO, DateTime? Report_BuyStandAlone_ExchangeDate, int Report_BuyStandAlone_PropertyTypeID)
        {

            string sSql = "select * from t_Report_BuyStandAlone where Report_BuyStandAlone_ExchangeTypeID=" + Report_BuyStandAlone_ExchangeTypeID+" and 1=1 ";
            if (Report_BuyStandAlone_ReportNO != "") sSql += "and Report_BuyStandAlone_ReportNO='" + Report_BuyStandAlone_ReportNO+"' ";
            if (Report_BuyStandAlone_ExchangeDate != null) sSql += "and Report_BuyStandAlone_ExchangeDate='" + Report_BuyStandAlone_ExchangeDate.ToString() + "' ";
            if (Report_BuyStandAlone_PropertyTypeID != 0) sSql += "and Report_BuyStandAlone_PropertyTypeID=" + Report_BuyStandAlone_PropertyTypeID;

            SqlCommand cmdToExecute = new SqlCommand();
            SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
            DataSet ds = new DataSet();

            cmdToExecute.CommandText = sSql;
            cmdToExecute.CommandType = CommandType.Text;

            try
            {
                cmdToExecute.Connection = _mainConnection;
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Open();
                }
                else
                {
                    if (_mainConnectionProvider.IsTransactionPending)
                    {
                        cmdToExecute.Transaction = _mainConnectionProvider.CurrentTransaction;
                    }
                }

                adapter.Fill(ds);

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                if (_mainConnectionIsCreatedLocal)
                {
                    _mainConnection.Close();
                }

                cmdToExecute.Dispose();

                adapter.Dispose();
            }

            return ds;
        }
        #endregion

        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="id">主键ID</param>
        /// <param name="audit">审核步骤</param>
        /// <returns></returns>
        public bool AuditByID(string id, string audit)
        {
            string sSql = "update t_Report_BuyStandAlone set Report_Plan_Audit=" + audit + " where Report_BuyStandAlone_ID='" + id + "'";
            return RunNoneSQL(sSql);
        }


        /// <summary>
        /// 获取项目名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public string getProjectName(string id)
        {
            string sSql = "select Project_Name from t_Project where Project_ID='" + id + "'";
            string toReturn = "";
            DataTable dt = RunSQL(sSql).Tables[0];
            if (dt.Rows.Count > 0)
            {
                toReturn = dt.Rows[0][0].ToString();
            }
            return toReturn;
        }
    }
}
